package cn.torna.example.common;

import java.io.Serializable;

/**
 * 返回结果
 * @author thc
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 6727183389225229653L;

    /**
     * 返回码,0表示成功，其它失败
     * @mock 0
     */
    private int code;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 错误消息
     * @mock OK
     */
    private String msg = "OK";

    public static <E> Result<E> ok(E data) {
        Result<E> result = new Result<>();
        result.setCode(0);
        result.setData(data);
        return result;
    }

    public static <E> Result<E> ok() {
        return ok(null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
